var Runner=function(){
    var f=function(v,pbar,btn,cb){
        return function(){
            if(v==1){
                //启动按钮
                btn.dom.disabled=false;
                cb();
            }else{
                pbar.updateProgress(v,'Loading item'+v+'%');
            }
        };
    }
    
    return{
        run:function(pbar,btn,count,cb){
            btn.dom.disabled=true;
            var runner=new Ext.util.TaskRunner();       
            var task={
                run:function(){
                    Ext.Ajax.request({                  //调用Ajax发送请求到后台
                        url:'../hf/servlet/FileUploadProgressServlet',                  //删除grid数据的url.
                        success:function(transport){                //处理成功后返回的函数
                            var oXmlDom=transport.responseText;
                            if(oXmlDom==1){
                                runner.stop(task);
                            }
                            f(oXmlDom,pbar,btn,cb)();
                        },
                        failure:function(){             //处理后台删除失败的函数
                            Ext.MessageBox.alert('消息','删除失败!');
                        }
                    });
                },
                interval:100
            };
            
            runner.start(task);

        }
    };
}();

Ext.onReady(function(){
    /*
    var pbar=new Ext.ProgressBar({
        text:'Ready',
        id:'pbar',
        renderTo:'pbar'     
    });
    var btn2=Ext.get('btn2');
    btn2.on('click',function(){
        Runner.run(pbar,btn2,12,function(){
            pbar.reset();
            pbar.updateText('Done.');
        });
    })
    
    var progressBar=new Ext.ux.ProgressBar({
        text:'Ready',
        id:'pbar',
        el:'pbar',
        url:'../hf/servlet/FileUploadProgressServlet'
    });
    var taskRunner=new Ext.util.TaskRunner();
    progressBar.setTaskRunner(taskRunner);
    var btn2=Ext.get('btn2');
    btn2.on('click',function(){
        progressBar.start();
    })
    */
    var progressBar=new Ext.ux.ProgressBar({
        text:'Ready',
        labelText:'progressBar1',
        id:'pbar',
        el:'pbar',
        url:'../hf/register.do?action=uploadProgress',
        resetProgressURL:'../hf/register.do?action=resetProgress'
    });
    Ext.ux.ProgressManager.addProgressBar(progressBar);
    
    var progressBar2=new Ext.ux.ProgressBar({
        text:'Ready',
        labelText:'progressBar2',
        id:'pbar',
        el:'pbar',
        url:'../hf/servlet/FileUploadProgressServlet'
    });
    Ext.ux.ProgressManager.addProgressBar(progressBar2);
    
    Ext.ux.ProgressManager.show();
    var btn2=Ext.get('btn2');
    btn2.on('click',function(){
        Ext.ux.ProgressManager.each(function(progressManager){
            progressManager.start();
        });
    })
})
